<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, width=device-width">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<meta name="format-detection" content="telephone=no">
	<meta content="telephone=no" name="format-detection">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<link rel="stylesheet" media="screen and (max-width:900px)" href="/assets/stylesheets/style_wap.css" type="text/css" />
	<link rel="stylesheet" media="screen and (min-width:900px)" href="/assets/stylesheets/style_pc.css" type="text/css" />
	<title>忘记密码</title>
</head>
<body>
	<div class="topline" id="J_topline">
		<div class="content clearfix">
			<!-- wap  start-->
			<a href="javascript:;" id="J_back" class="tlback"></a>
			<p class="alic tltext">忘记密码</p>
			<!-- wap end -->
			<!-- pc  start -->
			<a href="index.html" class="tll"><img src="/assets/images/logo.png" class="tlli">会员管理系统</a>
			<!-- pc end -->
		</div>
	</div>
	<div class="forget content">
		<p class="fgtil">找回密码</p>
		<div class="lines">
<!--			<div class="line"><p class="ado">已验证手机：</p><p class="linet">1585445854</p></div> -->
			<div class="line"><p class="ado">已验证手机：</p><input class="J_ctrol ctrol" data-type="phone" data-target="phone" type="text" placeholder="" name="" id="J_phone"></div>
			<div class="line lineb"><p class="ado">请填写手机验证码：</p><input class="J_ctrol ctrol" data-target="yzm" type="text" placeholder="" name="" id="J_yzm"><a href="javascript:;" class="btn btn_yzm" id="J_btnyzm">获取短信验证码</a></div>
			<div class="line"><p class="ado">新登录密码：</p><input class="J_ctrol ctrol" data-target="pwd" type="password" placeholder="" name="" id="J_pwd"></div>
			<div class="line"><p class="ado">确认新登录密码：</p><input class="J_ctrol ctrol" data-target="pwdag" type="password" placeholder="" name="" id="J_pwdag"></div>
			<div class="line linea"><a href="javascript:;" class="btn" id="J_btn">确认</a></div>
		</div>
	</div>
	<nav th:replace="hjh/include::bottomV"></nav>
	<script language="javascript" type="text/javascript" src="/assets/javascript/jquery-2.1.4.min.js"></script>
	<script language="javascript" type="text/javascript" src="/assets/javascript/func.js"></script>
	<script type="text/javascript">
		$(function(){


			$('.J_ctrol').blur(function(){
				var self = $(this),
					val = self.val().trim(),
					type = self.attr('data-type')||'text',
					tar = self.attr('data-target'),
					isright = true;

				if(type=="phone"){
			        if(!checkMobile(val)){
                        errormsg(self,'手机号不正确');
			            return;
			        };
				};
				if(val){
					self.val(val);
					data[tar] = val; // 数据填充
				};
			});

			var J_phone = $('#J_phone'),
				J_yzm = $('#J_yzm'),
				J_pwd = $('#J_pwd'),
				J_pwdag = $('#J_pwdag'),
				J_btnyzm = $('#J_btnyzm'),
				J_btn = $('#J_btn'),
				isajax = false, // 设置开关
				data = {};

			var timeb = 120,
				inter = '';
			J_btnyzm.click(function(){
				setTimeout(function(){
					sentyzm();
				},10);
			});

			function sentyzm(){
				if(isajax||timeb!=120){return false;};
				data.mobile = J_phone.val();
				if(!checkMobile(data.mobile)){
					errormsg(J_phone,'您输入的手机号不正确');
					return;
				};
				isajax = true;
				$.ajax({ // 发送验证码
					type: "POST",
					url: "sendVerification",
					data: JSON.stringify(data),
					contentType: "application/json",
					success: function(res){
						if(res.code==0){
							inter = setInterval(function(){
								timeb--;
								J_btnyzm.html(timeb+'秒后可重发');
								if(timeb<=0){
									clearInterval(inter);
									J_btnyzm.html('获取短信验证码');
									timeb = 120;
								};
							},1000);
						}else{
							errormsg(J_pwd,'发送失败')
						};
					},
					complete:function(){
						isajax = false;
					}
				});
			}


			J_btn.click(function(){
				if(isajax){return false;}
				data.mobile = J_phone.val();
				data.vcode = J_yzm.val();
				data.password = J_pwd.val();
				data.newPassword = J_pwdag.val();
				if(!data.mobile){
					errormsg(J_phone,'您输入的手机号不正确');
					return false;
				};
				if(!data.vcode){
					errormsg(J_yzm,'请输入验证码');
					return false;
				};
				if(!data.password ||data.password!=data.newPassword){
					errormsg(J_pwd,'输入的新密码两次不一致');
					return false;
				};

				//ajax提交数据
//				alert('提交的数据：'+JSON.stringify(data));
				isajax = true;
				J_btn.html("正在提交···");
				$.ajax({
					type: "POST",
					url: "forgetPassword",
					data: JSON.stringify(data),
					dataType: "json",
					contentType: "application/json",
					success: function(res){
						if(res.code==0){
							// 提交成功
							window.location.href = 'forgetState'; // 跳转
						}else{
						    if(res.code == 100){
                                errormsg(J_phone,res.msg);
							}else if(res.code == 101){
                                errormsg(J_pwd,res.msg);
							}else if(res.code == 102){
                                errormsg(J_yzm,res.msg);
							}else {
								alert(res.msg);
							}

							J_btn.html("提交");
						};
					},
					complete:function(){
						isajax = false;
					}
				});

			});
		});

        function checkMobile(mobile) {
            var reg = /^1[34578][0-9]{9}$/; //验证规则，
            return reg.test(mobile); //true
        }
	</script>
</body>
</html>
